package com.ltmonitor.web.mq;

import javax.annotation.Resource;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.ObjectMessage;

import com.ltmonitor.service.IAlarmPushService;
import com.ltmonitor.vo.AlarmMessage;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.socket.TextMessage;

import com.ltmonitor.web.controller.websocket.AlarmWebSocketHandler;
import com.ltmonitor.web.controller.websocket.MyWebSocketHandler;


public class AlarmMessageListener implements MessageListener {
	private static Logger logger = Logger.getLogger(AlarmMessageListener.class);

	@Autowired
	private IAlarmPushService alarmPushService;

	// 当收到消息后，自动调用该方法
	@Override
	public void onMessage(Message message) {

		ObjectMessage tm = (ObjectMessage) message;
		try {
//			logger.error("QueueMessageListener监听到消息：\t" + tm.getObject());
//			System.out.println("QueueMessageListener监听到消息：\t" + tm);
			alarmPushService.pushAlarm((AlarmMessage)tm.getObject());
		} catch (Exception e) {
			logger.error(e.getMessage(),e);
		}
	}

}
